package com.team.utils;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
@Data
@AllArgsConstructor
@Slf4j
@NoArgsConstructor
@Component
public class JwtUtil {
    @Value("${team.jwt.signKey}")
    private String signKey;
    @Value("${team.jwt.expire}")
    private  Long expire;

    public  String getJwt(Map<String, Object> claims)
        {
            return Jwts.builder()
                    .signWith(SignatureAlgorithm.HS256, signKey)
                    .setClaims(claims)
                    .setExpiration(new Date(System.currentTimeMillis()+expire))
                    .compact();
        }

    public Map<String, Object> parceJwt(String jwt)
        {
            return Jwts.parser()
                    .setSigningKey(signKey)
                    .parseClaimsJws(jwt)
                    .getBody();
        }

}
